<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
    }
    img{
        position: absolute;
        width: 100px;
    }
</style>
<body>
    <img src="download (1).gif" alt="">
</body>
<script>
    var imgs = document.querySelector('img');
    var leaderx = 0; //步长
    var targerx = 0; //目标值
    var leadery = 0; //步长
    var targery = 0; //目标值
    //鼠标点击事件
    document.onclick = function(event){
        event = event || event.document; //浏览器兼容性 用于IE5，6，7，8
        targerx = event.clientX - imgs.offsetWidth / 2
        targery =event.clientY - imgs.offsetHeight / 2
    }
    function fn(){
        leaderx = leaderx + (targerx-leaderx)/ 10
        leadery = leadery + (targery-leadery)/ 10

        imgs.style.left = leaderx+'px'
        imgs.style.top = leadery+'px'

    }
    //定时器 调用fn 每30毫秒运行一次
    setInterval(fn,30)
</script>
</html>